<template>
  <div>
    <el-card>
      <div style="padding: 0 0 20px 0;">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>用户管理</el-breadcrumb-item>
          <el-breadcrumb-item>用户</el-breadcrumb-item>
        </el-breadcrumb>
      </div>

      <el-form ref="form" :model="form" label-width="80px" :inline="true">
        <el-form-item>
          <el-input
            v-model="form.title"
            clearable
            placeholder="请输入关键字"
            class="input-with-select"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch()">搜索</el-button>
        </el-form-item>
      </el-form>
      
      <el-table :data="dataList" border>
        <el-table-column label="编号" prop="id"></el-table-column>
        <el-table-column label="手机号" prop="tel"></el-table-column>
        <el-table-column label="用户名" prop="username"></el-table-column>
        <el-table-column label="性别" prop="sex">
          <template slot-scope="scope">
            {{ scope.row.sex == 1 ? '男' : scope.row.sex == 2 ? '女' : '未知' }}
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="status">
          <template slot-scope="scope">
            {{
              scope.row.status == 1
                ? '通过'
                : scope.row.sex == 2
                ? '拒绝'
                : '待省'
            }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="250px">
          <template slot-scope="scope">
            <el-button type="primary" @click="edit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :total="total"
        :current-page="query.page"
        :page-size="10"
        @current-change="changePage"
      ></el-pagination>
      <div style="height: 20px;"></div>
    </el-card>

    <el-dialog :visible.sync="showEditUser" title="编辑用户">
      <edituser :data="curData" @success="editSuccess"/>
    </el-dialog>
  </div>
</template>

<script>
import { page } from '@/api/user/user.js';
import edituser from './components/edituser.vue';
export default {
  components: {
    edituser,
  },
  data() {
    return {
      form: {},
      showEditUser:false,
      query: {
        page: 1,
      },
      total: 0,
      dataList: [],
      curData:{},
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      page(this.query).then((res) => {
        console.log(res, 'res');
        this.dataList = res.data.data;
        this.total = res.data.total;
      });
    },
    changePage(e) {      
      this.query.page = e;
      this.getData()
    },
    editSuccess(){
      this.showEditUser = false;
      this.getData()
    },
    add() {},
    edit(row){
      this.curData = row;
      this.showEditUser = true;
    },
    onSearch() {},
  },
};
</script>

<style scoped></style>
